home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 November: Tool Chest / Dev.CD Nov 98 TC.toast / Tool Chest / Text / WASTE 1.3a6 / Demo / Source / WEDemoIntf.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-12-01  |  9.8 KB  |  442 lines  |  [TEXT/CWIE]

  1. /*
  2.     WASTE Demo Project:
  3.     Demo Header
  4.  
  5.     Copyright © 1993-1997 Marco Piovanelli
  6.     All Rights Reserved
  7.  
  8.     C port by John C. Daub
  9. */
  10.  
  11. /*
  12.     Due to differences between Pascal and C, this file (nothing like it originally existed
  13.     in the original Pascal code) was neccessary to create.  In it contains various macros,
  14.     constants, type and class declarations, function prototypes, etc..  From the original
  15.     code, some of this material would be spread amongst the source files, but a good
  16.     majority of this file comes from the WEDemoIntf.p file (the declarations, constants, etc).
  17.     There still is a WEDemoIntf.c file in the project tho since the .p file had a few
  18.     utility functions declared and defined in it.
  19. */
  20.  
  21. #ifndef __WEDEMOAPP__
  22. #define __WEDEMOAPP__
  23.  
  24. #ifndef __TYPES__
  25. #include <Types.h>
  26. #endif
  27.  
  28. #ifndef __RESOURCES__
  29. #include <Resources.h>
  30. #endif
  31.  
  32. #ifndef __QUICKDRAW__
  33. #include <QuickDraw.h>
  34. #endif
  35.  
  36. #ifndef __MENUS__
  37. #include <Menus.h>
  38. #endif
  39.  
  40. #ifndef __WINDOWS__
  41. #include <Windows.h>
  42. #endif
  43.  
  44. #ifndef __CONTROLS__
  45. #include <Controls.h>
  46. #endif
  47.  
  48. #ifndef __STANDARDFILE__
  49. #include <StandardFile.h>
  50. #endif
  51.  
  52. #ifndef _WASTE_
  53. #include "WASTE.h"
  54. #endif
  55.  
  56. #ifndef _LIMITS
  57. #include "limits.h"
  58. #endif
  59.  
  60.  
  61. /*
  62.  *    Some utility macros.
  63.  */
  64.  
  65.  
  66.  
  67. //     "Originally," these are things built into the Pascal language
  68. //     but since C doesn't have anything like them, and in an attempt to keep the code readable
  69. //     and similar to the original Pascal source, these #define macros work nice.
  70.  
  71.  
  72. #define BTST( FLAGS, BIT )    (((FLAGS) & (1L << (BIT))) ? 1 : 0)
  73. #define BSET( FLAGS, BIT )  ((FLAGS) |= (1L << (BIT)))
  74. #define BCLR( FLAGS, BIT )  ((FLAGS) &= (~(1L << (BIT))))
  75.  
  76. #define ABS(A) ((A) > 0 ? (A) : -(A))
  77.  
  78. #define BSL(A, B)    (((long) (A)) << (B))
  79. #define BSR(A, B)    (((long) (A)) >> (B))
  80. #define BOR(A, B)    ((A) | (B))
  81. #define BAND(A, B)    ((A) & (B))
  82.  
  83. #ifndef HiWrd
  84. #define HiWrd(aLong)        (((aLong) >> 16) & 0xFFFF )
  85. #endif
  86. #ifndef LoWrd
  87. #define LoWrd(aLong)        ((aLong) & 0xFFFF )
  88. #endif
  89.  
  90. enum {
  91.  
  92. //    WASTE Demo signature
  93.  
  94.     sigWASTEDemo        =        'OEDE',
  95.  
  96. //    resource types, clipboard types, and file types
  97.  
  98.     kTypeDeskAccessory    =        'DRVR',
  99.     kTypeFont            =        'FONT',
  100.     kTypeFontTable        =        'FISH',
  101.     kTypePicture        =        'PICT',
  102.     kTypeSound            =        'snd ',
  103.     kTypeSoup            =        'SOUP',
  104.     kTypeStyles            =        'styl',
  105.     kTypeText            =        'TEXT'
  106. };
  107.  
  108. enum {
  109.  
  110. //    virtual key codes for navigation keys found on extended keyboards
  111.  
  112.     keyPgUp                =        0x74,
  113.     keyPgDn                =        0x79,
  114.     keyHome                =        0x73,
  115.     keyEnd                =        0x77,
  116.  
  117. //    virtual key codes generated by some function keys
  118.  
  119.     keyF1                =        0x7A,
  120.     keyF2                =        0x78,
  121.     keyF3                =        0x63,
  122.     keyF4                =        0x76
  123. };
  124.  
  125. //    possible values for HandleOpenDocument refCon parameter
  126.  
  127. enum {
  128.     kDoOpen        = 0,
  129.     kDoPrint    = 1
  130. };
  131.  
  132. //     other commonly used constants
  133.  
  134. #define    kBarWidth                        16            // width of a scroll bar
  135. #define kTitleHeight                    20            // usual height of a window title bar
  136. #define kTextMargin                        3            // indent of text rect from a window port rect
  137. #define kScrollDelta                    11            // pixels to scroll when the scroll bar arrow is clicked
  138. #define kStandardTranslucencyThreshold    16384        // 16K sq pixels
  139.  
  140. #define kMinSystemVersion                0x0700        //    MacOS 7.0
  141. #define kMinWASTEVersion                0x01304002    //    WASTE 1.3a2
  142. #define kScrapThreshold                    4 * 1024    //    4 KB
  143.  
  144. // enumeration types used for closing a window and/or quitting the application
  145.  
  146. typedef enum {closingWindow, closingApplication} ClosingOption;
  147. typedef enum {savingYes, savingNo, savingAsk} SavingOption;
  148.  
  149. // enumeration for orientation (vertical/horizontal)
  150.  
  151. typedef enum {kVertical, kHorizontal} Orientation;
  152.  
  153. /*
  154.  *    Resource ID numbers
  155.  */
  156.  
  157. // menu IDs
  158.  
  159. enum {
  160.     kMenuApple        = 1,
  161.     kMenuFile,
  162.     kMenuEdit,
  163.     kMenuFont,
  164.     kMenuSize,
  165.     kMenuStyle,
  166.     kMenuColor,
  167.     kMenuFeatures,
  168.     kMenuAlignment,
  169.     kMenuDirection
  170. };
  171.  
  172. //    Apple Menu items
  173.  
  174. enum {
  175.     kItemAbout        = 1
  176. };
  177.  
  178. //    File menu items
  179.  
  180. enum {
  181.     kItemNew        = 1,
  182.     kItemOpen        = 2,
  183.     kItemClose        = 4,
  184.     kItemSave        = 5,
  185.     kItemSaveAs        = 6,
  186.     kItemQuit        = 8
  187. };
  188.  
  189. //    Edit menu items
  190.  
  191. enum {
  192.     kItemUndo        = 1,
  193.     kItemCut        = 3,
  194.     kItemCopy        = 4,
  195.     kItemPaste        = 5,
  196.     kItemClear        = 6,
  197.     kItemSelectAll    = 7
  198. };
  199.  
  200. //    Size menu items
  201.  
  202. enum {
  203.     kItemLastSize    = 6,
  204.     kItemSmaller    = 8,
  205.     kItemLarger        = 9,
  206.     kItemOtherSize    = 11
  207. };
  208.  
  209. //    Style menu items
  210.  
  211. enum {
  212.     kItemPlainText    = 1,
  213.     kItemBold,
  214.     kItemItalic,
  215.     kItemUnderline,
  216.     kItemOutline,
  217.     kItemShadow,
  218.     kItemCondensed,
  219.     kItemExtended
  220. };
  221.  
  222. //    Color menu items
  223.  
  224. enum {
  225.     kItemLastColor    = 7,
  226.     kItemOtherColor = 9
  227. };
  228.  
  229. //    Alignment menu items
  230.  
  231. enum {
  232.     kItemAlignDefault    = 1,
  233.     kItemAlignLeft        = 3,
  234.     kItemCenter,
  235.     kItemAlignRight,
  236.     kItemJustify
  237. };
  238.  
  239. //    Direction menu items
  240.  
  241. enum
  242. {
  243.     kItemDirectionDefault = 1 ,
  244.     kItemDirectionLR = 3 ,
  245.     kItemDirectionRL
  246. } ;
  247.  
  248. //    Features menu items
  249.  
  250. enum {
  251.     kItemAlignment            = 1,
  252.     kItemDirection            = 2,
  253.     kItemTabHooks            = 3,
  254.     kItemAutoScroll            = 5,
  255.     kItemOutlineHilite        = 6,
  256.     kItemReadOnly            = 7,
  257.     kItemIntCutAndPaste     = 8,
  258.     kItemDragAndDrop        = 9,
  259.     kItemTranslucentDrags    = 10,
  260.     kItemOffscreenDrawing    = 11
  261. };
  262.  
  263.  
  264. //    Alert & dialog template resource IDs
  265.  
  266. enum {
  267.     kAlertNeedSys7            = 128,
  268.     kAlertNeedNewerWASTE    = 129,
  269.     kAlertGenError            = 130,
  270.     kAlertSaveChanges        = 131,
  271.     kDialogAboutBox            = 256
  272. };
  273.  
  274. //    String list resource IDs
  275.  
  276. enum {
  277.     kUndoStringsID                = 128,
  278.     kClosingQuittingStringsID    = 129,
  279.     kMiscStringsID                = 130
  280. };
  281.  
  282. // miscellaneous resource IDs
  283.  
  284. enum {
  285.     kMenuBarID                = 128,
  286.     kWindowTemplateID        = 128,
  287.     kScrollBarTemplateID    = 128,
  288.     kPromptStringID            = 128
  289. };
  290.  
  291. // a DocumentRecord is a structure associated with each window
  292. // a handle to this structure is kept in the window refCon
  293.  
  294. struct DocumentRecord
  295. {
  296.     WindowRef            owner;                // the window
  297.     ControlRef            scrollBars [ 2 ];    // its scroll bars
  298.     WEReference         we;                    // its WASTE instance
  299.     Handle                 fileAlias;            // alias to associated file
  300. };  // DocumentRec
  301.  
  302. typedef struct DocumentRecord DocumentRecord, *DocumentPtr, **DocumentHandle;
  303.  
  304.  
  305. /*
  306.  *    The external declaration of some global variables.
  307.  */
  308.  
  309. //  These are defined in WEDemoIntf.c
  310.  
  311. extern    Boolean        gHasColorQD;        // true if Color QuickDraw is available
  312. extern    Boolean        gHasDragAndDrop;    // true if Drag Manager is available
  313. extern    Boolean        gHasTextServices;    // true is the Text Services Manager is available
  314. extern    Boolean        gExiting;            // set this variable to drop out of the event loop and quit
  315.  
  316. /*
  317.  *    Function Prototypes
  318.  */
  319.  
  320. //    From DialogUtils.c
  321.  
  322. ModalFilterUPP    GetMyStandardDialogFilter( void );
  323. short            GetDialogItemType( DialogRef, short );
  324. Handle            GetDialogItemHandle( DialogRef, short );
  325. void            GetDialogItemRect( DialogRef, short, Rect * );
  326. void            SetDialogItemProc( DialogRef, short, UserItemUPP );
  327. void            FlashButton( DialogRef, short );
  328.  
  329. //    From LongControls.c
  330.  
  331. OSErr            LCAttach( ControlRef );
  332. void            LCDetach( ControlRef );
  333. void            LCSetValue( ControlRef, long );
  334. void            LCSetMin( ControlRef, long );
  335. void            LCSetMax( ControlRef, long );
  336. long            LCGetValue( ControlRef );
  337. long            LCGetMin( ControlRef );
  338. long            LCGetMax( ControlRef );
  339. void            LCSynch( ControlRef );
  340.  
  341.  
  342. //    From WEDemoIntf.c
  343.  
  344. DocumentHandle    GetWindowDocument(WindowRef);
  345. #if __cplusplus
  346. inline WEReference GetWindowWE(WindowRef window) { return (* GetWindowDocument(window))->we; }
  347. #else
  348. #define GetWindowWE(window) (* GetWindowDocument(window))->we
  349. #endif
  350. void            ErrorAlert( OSErr );
  351. void            ForgetHandle( Handle * );
  352. void            ForgetResource( Handle * );
  353. void            BlockClr ( void *, Size ) ;
  354. OSErr            NewHandleTemp( Size, Handle * );
  355. void            PStringCopy( ConstStr255Param, Str255 );
  356.  
  357. //    From WEDemoAbout.c
  358.  
  359. OSErr            WETextBox( short, const Rect *, WEAlignment );
  360. void            DoAboutBox( short );
  361.  
  362. //    From WEDemoDrags.c
  363.  
  364. OSErr            InstallDragHandlers( void );
  365. OSErr            RemoveDragHandlers( void );
  366.  
  367. //    From WEDemoEvents.c
  368.  
  369. void            AdjustCursor( Point, RgnHandle );
  370. void            DoMouseDown( const EventRecord * );
  371. void            DoKeyDown( const EventRecord * );
  372. void            DoDiskEvent( const EventRecord * );
  373. void            DoOSEvent( const EventRecord * );
  374. void            DoHighLevelEvent( const EventRecord * );
  375. void            DoNullEvent( const EventRecord * );
  376. void            DoWindowEvent( const EventRecord *);
  377. void            ProcessEvent( void );
  378. OSErr            GotRequiredParams( const AppleEvent * );
  379. OSErr            InitializeEvents( void );
  380.  
  381. // from WEDemoFiles.c
  382.  
  383. OSErr            ReadTextFile( const FSSpec *, WEReference );
  384. OSErr            WriteTextFile( const FSSpec *, WEReference );
  385. pascal OSErr    TranslateDrag( DragReference, ItemReference, FlavorType, Handle );
  386. pascal OSErr    CheckObjectLock( short, long, StringPtr );
  387. pascal OSErr    FSpCheckObjectLock( const FSSpec * );
  388.  
  389. // from WEDemoInit.c
  390.  
  391. OSErr            Initialize( void );
  392. void            Finalize( void );
  393.  
  394. // from WEDemoMenus.c
  395.  
  396. void            SetDefaultDirectory( const FSSpec * );
  397. short            FindMenuItemText( MenuRef, ConstStr255Param );
  398. Boolean            EqualColor( const RGBColor *, const RGBColor * );
  399. void            PrepareMenus( void );
  400. void            DoDeskAcc( short );
  401. OSErr            DoNew( void );
  402. OSErr            DoOpen( void );
  403. OSErr            SaveWindow( const FSSpec *, WindowRef );
  404. OSErr            DoSaveAs( const FSSpec *, WindowRef );
  405. OSErr            DoSave( WindowRef );
  406. OSErr            DoClose( ClosingOption, SavingOption, WindowRef );
  407. OSErr            DoQuit( SavingOption );
  408. void            DoAppleChoice( short );
  409. void            DoFileChoice( short );
  410. void            DoEditChoice( short );
  411. void            DoFontChoice( short, EventModifiers );
  412. void            DoSizeChoice( short );
  413. void            DoStyleChoice( short );
  414. void            DoColorChoice( short );
  415. void            DoAlignmentChoice( short );
  416. void            DoDirectionChoice ( short ) ;
  417. void            DoFeatureChoice( short );
  418. void            DoMenuChoice( long, EventModifiers );
  419. OSErr            InitializeMenus( void );
  420.  
  421. // from WEDemoScripting.c
  422.  
  423. OSErr            WEGetContentsDesc( long, long, Boolean, AEDesc *, WEReference );
  424. OSErr            WESetContentsDesc( long, long, const AEDesc *, WEReference );
  425. OSErr            InstallCoreHandlers( void );
  426.  
  427. // from WEDemoWindows.c
  428.  
  429. void            DoDrag( Point, WindowRef );
  430. void            DoGrow( Point, WindowRef );
  431. void            DoZoom( short, WindowRef );
  432. Boolean            DoContent( Point, const EventRecord *, WindowRef );
  433. void            DoKey( short, const EventRecord * );
  434. void            DoUpdate( WindowRef );
  435. void            DoActivate( Boolean, WindowRef );
  436. OSErr            CreateWindow( const FSSpec * );
  437. void            DestroyWindow( WindowRef );
  438. void            Resize( Point, WindowRef );
  439.  
  440.  
  441. #endif /* __WEDEMOAPP__ */
  442.